<template>
  <!-- 孔德嘉 特色diy项目 2023年4月4日15点53分  -->
  <div>
    <!-- 特色diy -->
    <div class="characteristic">
      <h1
        style="
          text-align: center;
          letter-spacing: 10px;
          font-family: 'Times New Roman', Times, serif;
          font-weight: 400;
          margin: 30px 0 40px 0;
        "
      >
        DIY新物种
      </h1>
      <!-- 轮播图 -->
      <el-carousel
        :interval="4000"
        type="card"
        height="340px"
        style="width: 70%; margin: 0 auto"
        @change="characteristicChange"
      >
        <el-carousel-item
          v-for="(item, index) in characteristicList"
          :key="index"
          style="text-align: center; background-color: transparent"
        >
          <div class="characteristic_i" @click="toDIYView(item.id)">
            <!-- 图片 -->
            <el-image
              :src="$imageUrl + '?id=' + item.diyImageId"
              style="width: 240px; height: 240px"
              fit="cover"
            >
              <div slot="placeholder">
                <Loading></Loading>
              </div>
            </el-image>
            <!-- 内容 -->
            <div class="characteristic_text">
              <p
                style="
                  font-size: 14px;
                  font-weight: bold;
                  color: #333;
                  margin: 10px 0;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  white-space: nowrap;
                  text-align: left;
                  padding-left: 20px;
                "
              >
                {{ item.diyName }}
              </p>
              <p
                style="margin: 0 0 10px 0; text-align: left; padding-left: 20px"
              >
                <span style="color: #cc3124; font-size: 20px; font-weight: 700;display:inline-block;width:40%" 
                  >￥{{ item.diyFavorablePrice }}</span
                >
                <button class="cta">
                  <span>立即抢购</span>
                  <svg viewBox="0 0 13 10" height="10px" width="15px">
                    <path d="M1,5 L11,5"></path>
                    <polyline points="8 1 12 5 8 9"></polyline>
                  </svg>
                </button>
              </p>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>
  </div>
</template>

<script>
import Loading from "@/components/diy/Loading";
export default {
  name: "characteristicDIY",
  data() {
    return {
      //特色商品
      characteristicList: [],
    };
  },
  mounted() {
    this.getHandworkDiyListByCharacteristic();
  },
  components: { Loading },
  methods: {
    // 跳转到DIY商品详情页面
    toDIYView(id) {
      this.$router.push({
        path: "/DIYView",
        query: { diyId: id },
      });
    },
    // 查询DIY的特色商品方法
    getHandworkDiyListByCharacteristic() {
      this.$axios
        .get("/handworkDiy/getHandworkDiyListByCharacteristic")
        .then((res) => {
          // 获取特色商品数据
          this.characteristicList = res.data.data;
        })
        .catch(() => {
          this.$message.error("获取特色商品失败！");
        });
    },
    //改变轮播图
    characteristicChange(index) {
      // debugger
      const el = document.querySelectorAll(
        ".characteristic .el-carousel__item"
      );
      setInterval(() => {
        el.forEach((element) => {
          if (element.classList.contains("is-in-stage")) {
            element.style.transition = ".2s";
            element.style.opacity = "1";
          } else {
            element.style.transition = ".2s";
            element.style.opacity = "0";
          }
        });
      });
    },
  },
};
</script>

<style scoped>
/*特色DIy*/
.el-carousel__mask {
  background: transparent;
}
.characteristic {
  margin-top: 30px;
  padding-top: 10px;
  border-radius: 50px;
}
.characteristic_text {
  position: absolute;
  width: 240px;
  height: 70px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 1) 50%,
    rgba(255, 255, 255, 1) 100%
  );
}
.characteristic_i {
  margin: 0 auto;
  height: 330px;
  width: 240px;
  box-shadow: 8px 8px 10px #475669;
  border-radius: 2px;
  background: #fff;
}
.cta {
  margin-left: 15%;
  width: 44%;
  position: relative;
  padding: 12px 4px;
  transition: all 0.2s ease;
  border: none;
  background: none;
}

.cta:before {
  content: "";
  position: absolute;
  top: 3px;
  left: 0;
  display: block;
  border-radius: 50px;
  background: #fcf46196;
  width: 35px;
  height: 35px;
  transition: all 0.3s ease;
}

.cta span {
  position: relative;
  font-family: "Ubuntu", sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: #000000;
}

.cta svg {
  position: relative;
  top: 0;
  margin-left: 10px;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke: #000000;
  stroke-width: 2;
  transform: translateX(-5px);
  transition: all 0.3s ease;
}

.characteristic_i:hover .cta:before {
  width: 100%;
  background: #fcf46196;
}

.characteristic_i:hover svg {
  transform: translateX(0);
}

.characteristic_i:active .cta {
  transform: scale(0.95);
}
</style>